package com.sky.mapper.admin;

import com.github.pagehelper.Page;
import com.sky.aop.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description CategoryMapper
 * @Author lyh
 * @Date 2024-09-20
 */
@Mapper
public interface CategoryMapper {
    /**
     * 分页查询
     * @param dto
     * @return
     */
    Page<Category> pageQuery(CategoryPageQueryDTO dto);

    /**
     * 新增分类
     * @param category
     */
    @Insert("insert into category (type, name, status, create_time, update_time, create_user, update_user,sort) VALUES \n" +
            "    (#{type},#{name},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser},#{sort})")
    @AutoFill(value=OperationType.INSERT)
    void save(Category category);

    /**
     * 删除分类
     * @param id
     */
    @Delete("delete from category where id=#{id}")
    void delete(Integer id);

    /**
     * 修改分类
     * @param category
     */
    @AutoFill(value=OperationType.UPDATE)
    void update(Category category);
    /**
     * 启用禁用分类
     * @param status
     * @return
     */
    @Update("update category set status=#{status} where id=#{id}")
    void updateStatus(@Param("status") Integer status,@Param("id") Long id);

    /**
     * 根据类型查询分类
     * @param type =1  菜品分类    type= 2  套餐分类
     * @return
     */
    List<Category> list(Integer type);
    @Select("select * from category where id=#{id} ")
    Category getById(Integer id);
    @Select("select * from category where status=1")
    List<Category> list1();
}
